import request from './request'

// 视频分类接口
export interface VideoCategory {
  id: number
  name: string
}

// 视频分类响应
export interface VideoCategoryResponse {
  status: string
  message: string
  result: VideoCategory[]
}

// 视频数据接口
export interface VideoItem {
  id: number
  categoryId: number
  title: string
  shearUrl: string // 剪切视频url(试看)
  abstracts: string // 摘要
  originalUrl: string // 原始视频url
  price: number // 价格(H币)
  duration: number // 时长(单位/秒)
  whetherCollection: number // 是否收藏
  whetherBuy: number // 是否购买 1=是 2=否
  buyNum: number // 购买数
}

// 视频列表响应
export interface VideoListResponse {
  status: string
  message: string
  result: VideoItem[]
}

// 通用基础响应
export interface BaseResponse {
  status: string
  message: string
}

// 视频评论
export interface VideoCommentItem {
  id: number
  content: string
}

export interface VideoCommentListResponse {
  status: string
  message: string
  result: VideoCommentItem[]
}

/**
 * 获取视频分类列表
 * @returns Promise<VideoCategoryResponse>
 */
export const getVideoCategories = () => {
  return request.get<VideoCategoryResponse>('/health/user/video/v1/findVideoCategoryList')
    .then(response => response.data)
}

/**
 * 根据分类获取视频列表
 * @param categoryId 分类ID
 * @param page 页码
 * @param count 每页数量
 * @returns Promise<VideoListResponse>
 */
export const getVideoList = (categoryId: number, page: number = 1, count: number = 10) => {
  return request.get<VideoListResponse>('/health/user/video/v1/findVideoVoList', {
    params: {
      categoryId,
      page,
      count
    }
  }).then(response => response.data)
}

/**
 * 发表视频评论（弹幕）
 * 成功状态可能为 '0000' 或 '9001'（文档示例）
 */
export const addVideoComment = (videoId: number, content: string) => {
  return request.post<BaseResponse>('/health/user/video/verify/v1/addVideoComment', {
    videoId,
    content
  }).then(response => response.data)
}

/**
 * 查询视频评论列表
 */
export const getVideoCommentList = (videoId: number) => {
  return request.get<VideoCommentListResponse>('/health/user/video/v1/findVideoCommentList', {
    params: { videoId }
  }).then(response => response.data)
}
